package com.Interceptor.base;

import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;

/**
 * session拦截器
 * 
 * @author 孙宇
 * 
 */
public class SessionInterceptor extends MethodFilterInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Logger logger = Logger.getLogger(SessionInterceptor.class);
	
	private String msg="";	


	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		//SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ConfigUtil.getSessionInfoName());
		logger.info("验证登录情况，进入session拦截器->访问路径为[" + ServletActionContext.getRequest().getServletPath() + "]");
		
		Map session=actionInvocation.getInvocationContext().getSession();  
//      Users user=(Users)session.get("temploginbean");  
	      if(session.get("temploginbean")==null)  
	      {  	        
		        msg="您还没有登录或登录已超时，请重新登录！";
		        logger.info(msg+"session:"+session.get("temploginbean"));
		        ServletActionContext.getRequest().setAttribute("msg", msg);
		        return "noSession";  
	      }  
	      else  
	      {  
	      return actionInvocation.invoke();  
	      }  
		
		
		/*if ( ServletActionContext.getRequest().getSession().getAttribute("temploginbean")== null) {
			msg = "您还没有登录或登录已超时，请重新登录！";
			logger.info(msg);
			ServletActionContext.getRequest().setAttribute("msg", msg);
			return "noSession";
		}
		return actionInvocation.invoke();*/
	}


	public String getMsg() {
		return msg;
	}


	public void setMsg(String msg) {
		this.msg = msg;
	}

}
